import { CONFIRM_ACKNOWLEDGE, REJECT_ACKNOWLEDGE } from '@/constants/Command'
import { GetRequest, PostRequest, PutRequest, type Response } from '@/utils/request'
import type { Notice } from '@/types/notice'

/**
 * event推送dicision事件，点击取消
 * @param haId 家电haId
 * @param key 取消的event的key
 */

export function rejectEvent(haId: string, key: string): Promise<Response<string>> {
  return PutRequest(`/api/homeappliances/v1/${haId}/commands/${REJECT_ACKNOWLEDGE}`, {
    data: {
      key: REJECT_ACKNOWLEDGE,
      value: key,
    },
  })
}
/**
 * event推送dicision或adknowledge事件，点击确认
 * @param haId 家电haId
 * @param key 确认的event的key
 */

export function acknowledgeEvent(haId: string, key: string): Promise<Response<string>> {
  return PutRequest(`/api/homeappliances/v1/${haId}/commands/${CONFIRM_ACKNOWLEDGE}`, {
    data: {
      key: CONFIRM_ACKNOWLEDGE,
      value: key,
    },
  })
}

/**
 * 获取家电通知 ActionHandler
 */
export type ActionHandlerQuery = {
  key: string
  value: string | number | boolean | null
  brand: string
  type: string
  vib: string
}
export function getActionHandlerInfo(data: ActionHandlerQuery[]) {
  return PostRequest<Notice[]>('/api/content/iotplatform/actionhandler/info', data, { ignoreErrorTips: true })
}
